<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/10
 * Time: 9:01
 */

namespace Common\Model;


class ArticleModel extends CommonModel
{
    protected $pk        =  'id';
    protected $tableName =  'article';
    protected $token     =  'article';
    protected $orderby   =  array('orderby' => 'asc');

    //静态验证
    protected $_validate = array(
        array('name', 'title', '请填写文章名称！'),
        array('name', 'content', '请填写文章内容！'),
    );

    /**
     * 格式数据
     * @author Kevin_ren  <330202207@qq.com>
     */
    public function _format($data)
    {
        $categorys =  array_column(D('Category')->where(array('is_del' => 0))->select(), null,'id');

        if (!empty($data)) {
            $data['category_name']  =  $categorys[$data['category_id']]['name'];
        }

        return $data;
    }

    /**
     * 文章点击+1
     * @author Kevin_ren  <330202207@qq.com>
     */
    public function onclick($id)
    {
        $this->where(array('id' => $id))->setInc('click', 1);
    }

} 